import { reactive } from "vue";
import type { FormRules } from "element-plus";

/** 资讯表单验证规则 */
export const formRules = reactive<FormRules>({
  title: [
    {
      required: true,
      message: "资讯标题为必填项",
      trigger: "blur"
    },
    {
      min: 2,
      max: 100,
      message: "资讯标题长度应在 2 到 100 个字符之间",
      trigger: "blur"
    }
  ],
  categoryId: [
    {
      required: true,
      message: "请选择资讯分类",
      trigger: "change"
    }
  ],
  content: [
    {
      required: true,
      message: "资讯内容为必填项",
      trigger: "blur"
    },
    {
      min: 10,
      message: "资讯内容至少需要 10 个字符",
      trigger: "blur"
    }
  ],
  summary: [
    {
      max: 500,
      message: "资讯摘要不能超过 500 个字符",
      trigger: "blur"
    }
  ],
  author: [
    {
      max: 50,
      message: "作者名称不能超过 50 个字符",
      trigger: "blur"
    }
  ],
  source: [
    {
      max: 100,
      message: "来源不能超过 100 个字符",
      trigger: "blur"
    }
  ],
  status: [
    {
      required: true,
      message: "请选择发布状态",
      trigger: "change"
    }
  ],
  sort: [
    {
      required: true,
      message: "排序值为必填项",
      trigger: "blur"
    },
    {
      type: "number",
      min: 0,
      max: 9999,
      message: "排序值应在 0 到 9999 之间",
      trigger: "blur"
    }
  ],
  publishTime: [
    {
      type: "date",
      message: "请选择正确的发布时间",
      trigger: "change"
    }
  ],
  remark: [
    {
      max: 500,
      message: "备注不能超过 500 个字符",
      trigger: "blur"
    }
  ]
});

/** 搜索表单验证规则 */
export const searchFormRules = reactive<FormRules>({
  title: [
    {
      max: 100,
      message: "标题不能超过 100 个字符",
      trigger: "blur"
    }
  ],
  author: [
    {
      max: 50,
      message: "作者名称不能超过 50 个字符",
      trigger: "blur"
    }
  ]
});